'''
Created on 2017年10月3日

@author: lml
'''

import tensorflow as tf

if __name__ == '__main__':
    
    l = tf.Variable(tf.constant(value=1, dtype=tf.float32))
    l2 = tf.Variable(tf.constant(value=2, dtype=tf.float32))
    s = tf.Variable(tf.constant(value=[0], dtype=tf.int32))
    ema = tf.train.ExponentialMovingAverage(0.9)
    
    op = l.assign_add(1)
    op2 = l2.assign_add(1)
    
    with tf.control_dependencies([op, op2]):
        ma = ema.apply([l, l2])#更新参数

    sess = tf.Session()
    init = tf.global_variables_initializer()
    sess.run(init)
    for i in range(5):
        sess.run(ma)
        print(sess.run([l, ema.average(l)]))#获取值，使用引用作为key
        print(sess.run([l2, ema.average(l2)]))